package day10_io_code.com.itheima.d8_demo;

public class BeerDemo3 {
    public static int totalNumber;
    public static int lastBottleNumber;
    public static int lastCoverNumber;

    public static void main(String[] args) {
        buy(10);
        System.out.println("totalNumber = " + totalNumber);
        System.out.println("lastCoverNumber = " + lastCoverNumber);
        System.out.println("lastBottleNumber = " + lastBottleNumber);
    }
    public static void buy(int money){
        int number = money / 2;
        totalNumber += number;

        int totalBottleNumber = lastBottleNumber + number;
        int totalCoverNumber = lastCoverNumber + number;

        int allMoney = 0;
        if (totalBottleNumber >= 2){
            allMoney += (totalBottleNumber / 2) * 2;
        }
        lastBottleNumber = totalBottleNumber % 2;

        if (totalCoverNumber >= 4){
            allMoney += (totalCoverNumber / 4) * 2;
        }
        lastCoverNumber = totalCoverNumber % 4;
        if (allMoney >= 2){
            buy(allMoney);
        }
    }
}
